package com.hotel.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hotel.entity.OrderDetail;
import com.hotel.entity.Refund;
import com.hotel.response.Result;
import com.hotel.service.OrderDetailService;
import com.hotel.service.RefundService;
import com.hotel.vo.RefundVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Lin
 * @since 2022-06-20
 */
@Api(tags = "退货管理")
@RestController
@RequestMapping("/refund")
public class RefundController {

    @Resource
    private RefundService refundService;

    @Resource
    private OrderDetailService orderDetailService;

    @ApiOperation(value = "获取退货信息")
    @GetMapping("/getRefundList")
    public Result getRefundList(@RequestParam(value = "refundNo",required = false)String refundNo,
                                @RequestParam(value = "nickName",required = false) String nickName,
                                @RequestParam(value = "status",required = false)String status,
                                @RequestParam(value = "createTime",required = false)String createTime,
                                @RequestParam(value = "current",required = false,defaultValue = "1") Integer current,
                                @RequestParam(value = "size",required = false,defaultValue = "4")Integer size){
        IPage<Refund> refundList = refundService.getRefundList(refundNo,nickName, status, createTime, current, size);
        return Result.ok().data("refundList",refundList);
    }

    @ApiOperation(value = "退货详情")
    @RequiresPermissions({"refund:detail"})
    @GetMapping("/getRefundDetails")
    public Result getRefundDetails(@RequestParam(value = "refundNo") String refundNo){
        RefundVO refundDetails = refundService.getRefundDetails(refundNo);
        return Result.ok().data("refundDetails",refundDetails);
    }

    @ApiOperation(value = "商品信息")
    @GetMapping("/getOrderDetails")
    public Result getOrderDetails(@RequestParam(value = "orderId") String orderId){
        List<OrderDetail> orderDetail = orderDetailService.getOrderDetail(orderId);
        return Result.ok().data("orderDetail",orderDetail);
    }

}

